package com.whfc.hdc.queue;

import com.alibaba.fastjson.JSON;
import com.whfc.common.constant.QueueConst;
import com.whfc.hdc.manager.FshDeviceDataManager;
import com.whfc.hdc.params.FshDeviceDataParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author qzexing
 * @version 1.0
 * @date 2021-04-21 11:15
 */
@Component
@RabbitListener(queues = QueueConst.FSH_CURRENT_DATA)
public class FshCurrDataQueueMessageListener {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private FshDeviceDataManager fshDeviceDataManager;

    @RabbitHandler
    public void process(String msg) {
        try {
            logger.info("fsh_current_data, 智能安全帽数据消费:{}", msg);
            FshDeviceDataParam params = JSON.parseObject(msg, FshDeviceDataParam.class);
            fshDeviceDataManager.addDeviceData(params);
        } catch (Exception e) {
            logger.error("fsh_current_data, 智能安全帽数据消费异常", e);
        }
    }

}
